package logic

import (
	"context"

	"go-zero-service/service/user/api/internal/svc"
	"go-zero-service/service/user/api/internal/types"
	"go-zero-service/service/user/model"
	"go-zero-service/common/tool"
	"github.com/zeromicro/go-zero/core/logx"
)

type InfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
	return &InfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InfoLogic) Info(req *types.InfoReq, token string) (resp *types.InfoReply, err error) {
	// todo: add your logic here and delete this line
	var info model.User
	uuid,_ := tool.GetJwtUuid(token)
	result := l.svcCtx.UserModel.Where("uuid = ?", uuid).Find(&info)

	return &types.InfoReply{
		Id:       info.ID,
		Username: info.Username,
		Gender:   info.Gender,
	}, result.Error
}
